//
// Created by johnpank on 13.01.24.
//
#include "fsm.h"

//global variables
int temp = 0;
int speed = 0;
int c;

//utils func
void test(){
    printf("Includes work!!!\n");
}

void cls(){
    printf("\e[1;1H\e[2J");
}


//implementation state-handle function
state_type stop_handler(void){
    cls();
    printf("Device is ustopped\n");
    /*
    c = getchar();
    switch(c){
        case 'p':
            return ST_SET_TEMP;
            break;
    }
    */
    return ST_STOP;
};

state_type set_temp_handler(void){
    cls();
    printf("Set temperature\n");
    printf("Current temperature %d \n", temp);
    return ST_SET_TEMP;
};

state_type temp_up_handler(void){
    temp++;
//    printf("t+\n");
    return ST_TEMP_UP;
};

state_type temp_down_handler(void){
    if(temp > 0){
        temp--;
//        printf("t-\n");
    }
    return ST_TEMP_DOWN;
};

state_type set_motor_speed_handler(void){
    cls();
    printf("Set Motor speed\n");
    printf("Current speed %d\n", speed);
    return ST_SET_MOTOR_SPEED;
};

state_type motor_speed_up_handler(void){
    speed++;
    return ST_MOTOR_SPEED_UP;
};

state_type motor_speed_down_handler(void){
    if(speed > 0){
        speed--;
    }
    return ST_MOTOR_SPEED_DOWN;
};

state_type ask_start_no_handler(void){
    cls();
    printf("You are sure to start (NO)\n");
    return ST_ASK_START_NO;
};

state_type ask_start_yes_handler(void){
    cls();
    printf("You are sure to start (YES)\n");
    return ST_ASK_START_YES;
};

state_type start_handler(void){
    cls();
    printf("Device work\n");
    printf("Temperature: %d\n", temp);
    printf("Speed:       %d\n", speed);
    return ST_START;
};
